package com.xiaode.controller.app.student.binding;

import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.kit.Ret;
import com.xiaode.common.model.Student;
import com.xiaode.util.apidoc.annotation.Api;
import com.xiaode.util.apidoc.annotation.ApiOper;
import com.xiaode.util.apidoc.annotation.ApiPara;

import javax.validation.constraints.Size;

/**
 * 学生绑定老师相关服务
 *
 * @Author: 刘绪
 * @Date: 2022/3/11
 */
@Path("/sBindTeacher")
@Api("学生绑定老师相关服务")
@EnableCORS
public class BindTeacherController extends Controller {
    @Inject
    BindTeacherService service;

    /**
     * 查询学生绑定的老师
     */
    @ApiOper("查询学生绑定的老师")
    public void findBindTeacher() throws Exception {
        Student student = getAttr("user");
        Ret ret = service.findBindTeacher(student.getId());
        renderJson(ret);
    }

    /**
     * 查询教师列表
     *
     * @param curPage  当前页
     * @param pageSize 每页大小
     * @throws Exception
     */
    @ApiOper("查询老师列表")
    public void findTeachers(
            @Size(min = 1) @ApiPara(value = "curPage", notes = "当前页码") Integer curPage,
    		@Size(min = 1) @ApiPara(value = "pageSize", notes = "每页大小") Integer pageSize,
    		@ApiPara(value = "keyWord", notes = "关键词搜索") String keyWord) throws Exception {
        Ret ret = service.findTeachers(keyWord, curPage, pageSize);
        renderJson(ret);
    }

    /**
     * 学生绑定教师申请
     *
     * @param teacherId 教师id
     * @throws Exception
     */
    @ApiOper("学生绑定教师申请")
    public void stuBindTea(@Size @ApiPara(value = "teacherId", notes = "教师id") Integer teacherId) throws Exception {
        Student student = getAttr("user");
        Ret ret = service.stuBindTeacher(student.getId(), teacherId);
        renderJson(ret);
    }

    /**
     * 学生提交解绑申请
     *
     * @param teacherId 教师Id
     */
    @ApiOper("学生提交解绑申请")
    public void stuCancelBindTea(@Size @ApiPara(value = "teacherId", notes = "教师id") Integer teacherId) throws Exception {
        Student student = getAttr("user");
        Ret ret = service.stuCancelBindTea(student.getId(), teacherId);
        renderJson(ret);
    }


}
